package edu.cmu.cs.stage3.alice.core.question.ask;

import edu.cmu.cs.stage3.alice.core.property.StringProperty;
import edu.cmu.cs.stage3.resourceBundle.I18n;
import edu.cmu.cs.stage3.swing.DialogManager;

/**
 * @author Ben Buchwald, Dennis Cosgrove
 */

public class AskUserYesNo extends edu.cmu.cs.stage3.alice.core.question.BooleanQuestion {
	public final StringProperty title = new StringProperty( this, "title", "Question" );
	public final StringProperty question = new StringProperty( this, "question", I18n.getString("yesOrNo")+"?" );

	private edu.cmu.cs.stage3.alice.core.Clock m_clock;

	//Rem @Override
	public Object getValue() {
		if( m_clock != null ) {
			m_clock.pause();
		}
		try {
			int result = DialogManager.showConfirmDialog( question.getStringValue(), title.getStringValue(), javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE );
			return new Boolean( result == javax.swing.JOptionPane.YES_OPTION );
		} finally {
			if( m_clock != null ) {
				m_clock.resume();
			}
		}
	}

	//Rem @Override
	protected void started( edu.cmu.cs.stage3.alice.core.World world, double time ) {
		super.started( world, time );
		if( world != null ) {
			m_clock = world.getClock();
		} 
	}
	//Rem @Override
	protected void stopped( edu.cmu.cs.stage3.alice.core.World world, double time ) {
		m_clock = null;
		super.stopped( world, time );
	}
}